package search;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

//https://leetcode.cn/leetbook/read/illustration-of-algorithm/5viisg/
public class LCR_169招式拆解2 {
    //哈希表
    class Solution {
        public char dismantlingAction(String arr) {
            HashMap<Character, Boolean> map = new HashMap<>();
            char[] s = arr.toCharArray();
            for(char c : s)
                map.put(c,!map.containsKey(c));
            for(char c : s)
                if(map.get(c)) return c;
            return ' ';
        }
    }
    //有序哈希表
    class Solution2 {
        public char dismantlingAction(String arr) {
            HashMap<Character, Boolean> map = new LinkedHashMap<>();
            char[] s = arr.toCharArray();
            for(char c : s)
                map.put(c,!map.containsKey(c));
            for(Map.Entry<Character, Boolean> mapEntry : map.entrySet())
                if(mapEntry.getValue()) return mapEntry.getKey();
            return ' ';
        }
    }

    //库函数
    class Solution3 {
        public char dismantlingAction(String arr) {
            for(int i=0; i<arr.length(); i++){
                if(arr.indexOf(arr.charAt(i)) == arr.lastIndexOf(arr.charAt(i)))
                    return arr.charAt(i);
            }
            return ' ';
        }
    }
}
